package pl.edu.agh.bd2.domain;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Entity
@Table(name="subject")
public class Subject {
	
	@Id
	@GeneratedValue
	@NotNull
	private long id;
	
	@Column(name="name")
	private String name;
	
	@OneToMany(mappedBy = "subject")
	private Set<GradeType> gradeTypes;
	
	@ManyToMany
	@JoinTable(
			name="subjects_students",
			joinColumns=
				@JoinColumn(
					name="id_subject",
					referencedColumnName="id"
					),
			inverseJoinColumns=
				@JoinColumn(
					name="id_student",
					referencedColumnName="id"
					)
				)
	private Set<Student> students;
	
	
	@ManyToOne
	@JoinColumn(name="teacher")
	private Teacher teacher;
	
	@OneToMany(mappedBy = "subject")
	private Set<Topic> topics;

	protected Subject() {
	}

	public Subject(String name, Set<GradeType> gradeTypes,
			Set<Student> students, Teacher teacher, Set<Topic> topics) {
		super();
		this.name = name;
		this.gradeTypes = gradeTypes;
		this.students = students;
		this.teacher = teacher;
		this.topics = topics;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<GradeType> getGradeTypes() {
		return gradeTypes;
	}

	public void setGradeTypes(Set<GradeType> gradeTypes) {
		this.gradeTypes = gradeTypes;
	}

	public Set<Student> getStudents() {
		return students;
	}

	public void setStudents(Set<Student> students) {
		this.students = students;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public Set<Topic> getTopics() {
		return topics;
	}

	public void setTopics(Set<Topic> topics) {
		this.topics = topics;
	}

	public Student[] findStudent(Student aCriteria) {
		throw new UnsupportedOperationException();
	}

	public void addTopic(Topic topic) {
		topics.add(topic);
	}
	
	public void addStudent(Student aStudent) {
		students.add(aStudent);
	}

	public void addGradeType(GradeType aGt) {
		gradeTypes.add(aGt);
	}

	public String getReport() {
		throw new UnsupportedOperationException();
	}

	public double getStudentAverage(Student aSt) {
		throw new UnsupportedOperationException();
	}

	public double getTotalAverage() {
		throw new UnsupportedOperationException();
	}

	public void removeStudent(Student aSt) {
		throw new UnsupportedOperationException();
	}
}